StatusPanel = function() {
	
	// create the data store
	msgData = new Ext.data.SimpleStore({
		fields: [
			{name: 'msg', type: 'string'},
			{name: 'type', type: 'string'},
			{name: 'date', type: 'date'}
		],
		sortInfo:{field:'date', direction:'ASC'}
	});
	
	// create the grid
	statusGrid = new Ext.grid.GridPanel({
		store: msgData,
		columns: [
			{id:'msg',header: "Message", sortable: true, dataIndex: 'msg'},
			{header: "Type", sortable: true, dataIndex: 'type', renderer: function(value){
				switch (value) {
					case 'error':
						return '<span class="x-error">Error</span>';
						break;
					case 'warning':
						return '<span class="x-warning">Warning</span>';
						break;
					case 'notice':
						return '<span class="x-notice">Notice</span>';
						break;
					case 'debug':
						return '<span class="x-debug">Debug</span>';
						break;
					default:
						return value.toProperCase();
				}
			}},
			{header: "Date", width: 200, sortable: true, renderer: Ext.util.Format.dateRenderer(Date.patterns.FullDateTime), dataIndex: 'date'}
		],
		stripeRows: true,
		autoExpandColumn: 'msg',
		autoHeight: true
	});
	
	StatusPanel.superclass.constructor.call(this, {
		region:'south',
		id: 'statusPanel',
		autoScroll: true,
		split:true,
		height:200,
		minSize:100,
		maxSize:500,
		collapsible:true,
		title:'Status',
		iconCls:'status-icon',
		margins:'0 5 5 5',
		items: [statusGrid]
	});
	
	
/*	this.grid.getView().on('rowsinserted', function(){
		console.debug("here1");
		this.grid.getView().focusRow(10); // focus last row
	});*/
	
};

Ext.extend(StatusPanel, Ext.Panel, {
	log: function(data) {
		var record = Ext.data.Record.create([
			{name: 'msg', type: 'string'},
			{name: 'type', type: 'string'},
			{name: 'date', type: 'date'}
		]);
		
		var type = 'default';
		
		// if success is used set type appropriately
		if (typeof(data.success) != "undefined") {
			if (data.success) {
				type = 'notice';
			} else {
				type = 'error';
			}
		}
		
		// set defaults
		Ext.applyIf(data, {
			date: new Date,
			type: type
		});
		
		var row = new record(data);
		
		msgData.insert(0, row);
	
	}
});